﻿package leaf.science.ui.camera
{

import caurina.transitions.Tweener;

import com.util.Console;

import flash.display.FrameLabel;
import flash.events.Event;
import flash.events.MouseEvent;


public class DemosCamera extends Camera
{
	
	public var h1:DemoHotspot;
	public var h2:DemoHotspot;
	public var h3:DemoHotspot;
	public var h4:DemoHotspot;
	public var h5:DemoHotspot;
	public var h6:DemoHotspot;
	public var h7:DemoHotspot;
	public var h8:DemoHotspot;
	
	private var _hotspots:Array;
	private var _currentHotspot:DemoHotspot;
	

	public function DemosCamera()
	{
		stop();
		mouseEnabled = false;
		
		_hotspots = [h1, h2, h3, h4, h5, h6, h7, h8];
		
		h1.id = 0;
		h1.frame = 51;
		
		h2.id = 1;
		h2.frame = 1;
		
		h3.id = 2;
		h3.frame = 64;
		
		h4.id = 3;
		h4.frame = 77;
		
		h5.id = 4;
		h5.frame = 16;
		
		h6.id = 5;
		h6.frame = 1;
		
		h7.id = 6;
		h7.frame = 1;
		
		h8.id = 7;
		h8.frame = 91;
		
		this.addEventListener( MouseEvent.CLICK, onMouseClick, false, 0, true );
	}
	
	private function getHotspotById( id:uint ):DemoHotspot
	{
		for( var i:Number=0; i<_hotspots.length; i++ )
		{
			if( DemoHotspot( _hotspots[i] ).id == id )
				return( _hotspots[i] );			
		}
		return( null );
	}
	
	private function onMouseClick( evt:MouseEvent ):void
	{
		if( evt.target is DemoHotspot )
		{
			this.hotspot = evt.target as DemoHotspot;
		}
	}
	
	public function set hotspot( h:DemoHotspot ):void
	{
		gotoFrame( h.frame );
		_currentHotspot = h;
	}
	
	public function get hotspot():DemoHotspot
	{
		return( _currentHotspot );
	}
	
	public function set hotspotId( id:uint ):void
	{
		var h:DemoHotspot = getHotspotById( id );
		if( h )	this.hotspot = h;
	}
	
}
}